package com.poi.demo.util;

import com.poi.demo.parser.*;
import com.poi.demo.vo.WordContentParserVO;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

public class PoiUtil {

    /**
     * <p>word模板文字、表格、图表内容替换</p>
     *
     * @author Allen Yang
     * @datetime 2021/11/19 11:11
     */
    public static WordContentParser replaceWordContent(WordContentParserVO param) {
        XWPFDocument doc = WordContentParser.loadXWPFDocument(param.getPath());
        //文字替换
        WordParagraphParser paragraphParser = new WordParagraphParser(doc, param.getTextReplaceMap());
        paragraphParser.replace();

        //表格替换
        WordTableParser tableParser = new WordTableParser(doc, param.getTableReplaces(), param.getTextReplaceMap());
        tableParser.replace();

        //图表替换
        WordChartParser chartParser = new WordChartParser(doc, param.getChartReplaces());
        chartParser.replace();

        //图片替换
        WordPictureParser pictureParser = new WordPictureParser(doc, param.getPictureReplaces());
        pictureParser.replace();

        return chartParser;
    }

}
